//
//  News.cpp
//  symbrion
//
//  Created by Berend Weel on 4/16/13.
//  Copyright (c) 2013 Berend Weel. All rights reserved.
//

#include "News.h"

std::ostream& operator<<(std::ostream& out, const News& news) {
    out << "[news@" << news.getTimestamp() << ":";
    
    const Individual *individual = news.getIndividual();
    out << individual->id << ":";
    
    out << individual->sigma << ":";
    
    out << individual->fitness << ":";
    
    for(int i=0;i<individual->genome.size();i++){
        out << individual->genome[i];
        
        if(i < individual->genome.size()-1){
            out << ",";
        }
    }
    out << "]";
    
    return out;
}

bool operator==( const News& one, const News& other){
    bool rval = ((one.getTimestamp() == other.getTimestamp()) && (one.getIndividual()->id == other.getIndividual()->id));
    return rval;
}

bool operator<(const News& one, const News& other){
    if(one.getTimestamp() == other.getTimestamp()){
        return one.getIndividual()->id < other.getIndividual()->id;
    }else{
        return one.getTimestamp() < other.getTimestamp();
    }
}

bool operator>(const News& one, const News& other){
    if(one.getTimestamp() == other.getTimestamp()){
        return one.getIndividual()->id > other.getIndividual()->id;
    }else{
        return one.getTimestamp() > other.getTimestamp();
    }
}

bool newsLessThanp(News *one, News *other){
    if(one->getTimestamp() == other->getTimestamp()){
        return one->getIndividual()->id < other->getIndividual()->id;
    }else{
        return one->getTimestamp() < other->getTimestamp();
    }
}

bool newsGreaterThanp(News *one, News *other){
    if(one->getTimestamp() == other->getTimestamp()){
        return one->getIndividual()->id > other->getIndividual()->id;
    }else{
        return one->getTimestamp() > other->getTimestamp();
    }
}

bool newsEqualp(News *one, News *other){
    bool rval = ((one->getTimestamp() == other->getTimestamp()) && (one->getIndividual()->id == other->getIndividual()->id));
    return rval;
}

bool newsNotEqualp(News *one, News *other){
    return !newsEqualp(one,other);
}

bool newsLessThan(const News &one, const News &other){
    if(one.getTimestamp() == other.getTimestamp()){
        return one.getIndividual()->id < other.getIndividual()->id;
    }else{
        return one.getTimestamp() < other.getTimestamp();
    }
}

bool newsGreaterThan (const News &one, const News &other) {
    if(one.getTimestamp() == other.getTimestamp()){
        return one.getIndividual()->id > other.getIndividual()->id;
    }else{
        return one.getTimestamp() > other.getTimestamp();
    }
}

bool newsEqual(const News &one, const News &other){
    bool rval = ((one.getTimestamp() == other.getTimestamp()) && (one.getIndividual()->id == other.getIndividual()->id));
    return rval;
}

bool newsNotEqual(const News &one, const News &other){
    return !newsEqual(one,other);
}